Skip to main content

Tool Results

BindAI tools use ToolResult as their execution result type. ToolResult records:
  • whether execution succeeded
  • the value produced by the tool
  • an error message when execution failed
It provides a small, consistent result contract that can be used by tools, workflows, and the Studio runtime.

ToolResult

The V1 ToolResult is a dataclass that extends BindAI’s ExecutionResult:
Its fields are:
The fields are: ToolResult uses slots=True. The important distinction is:
  • successful execution is represented by success=True
  • the successful result is stored in value
  • failed execution is represented by success=False
  • failure information is stored in error

Creating Successful Results

ToolResult provides the ok() class method for creating a successful result:
This produces:
A successful result can also contain no value:
which represents:
None in value does not by itself indicate failure. Always use result.success to determine whether execution succeeded.

Creating Failed Results

ToolResult also provides the failed() class method:
The result is:
The failed() method accepts the failure message as a string. For example:
This keeps the failure representation consistent with the rest of the tool runtime.

Tool Implementations

The Tool base class defines the execution contract for class-based tools. A Tool implementation provides:
  • name
  • description
  • definition
  • execute(context)
The execute() method returns a ToolResult:
A successful execution therefore returns:
A failed execution can return:

Checking Success

Applications can inspect the success field:
This is the standard pattern for handling a ToolResult. For example:
Do not determine success solely by checking whether value is None. A successful tool can legitimately return:

Accessing the Returned Value

A successful tool value is available through value:
Output:
The field used by ToolResult for the tool’s successful value is:
This is the field to use when handling a ToolResult directly. Because ToolResult also extends ExecutionResult, BindAI’s broader execution-result interface can expose additional execution information where appropriate. The tool-specific successful value remains result.value.

Returning Different Python Values

Tools can produce normal Python values.

Strings

The value is:
and contains:

Numbers

The value is:

Lists

The value is the list:

Dictionaries

The dictionary is available through:
ToolResult.value accepts arbitrary Python values. The value should nevertheless be chosen with its downstream consumer in mind, particularly when the result will be passed into another workflow node or exposed through the Studio API.

None as a Successful Value

A tool can successfully complete without producing a meaningful value. For example:
represents:
This is different from:
The correct way to distinguish the two is:

Handling Tool Failures

A tool failure can be represented explicitly:
The caller can then inspect:
This produces a consistent failure representation without requiring callers to know how the underlying tool implemented the operation.

Exceptions and Tool Results

A Tool implementation controls the ToolResult returned from its execute() method. For example:
This explicitly converts the operation into the BindAI tool result contract. The error message should be useful to the caller without exposing secrets or other sensitive implementation details. For example, avoid putting credentials directly into an error message.

Tool Results in Workflows

Tools can be executed as workflow nodes. A Tool node can produce a ToolResult that becomes part of workflow execution state. Conceptually:
BindAI’s workflow runtime preserves the ToolResult object in workflow variables. This is important because workflow execution state is richer than the JSON representation returned by the Studio API. For example, a tool result can be stored as:
A subsequent workflow operation can work with that result according to the workflow’s configured mappings and execution behavior.

Tool Results and Parameter Mapping

When a Tool node is used in a workflow, its inputs can be mapped from workflow variables. For example:
The Tool node receives the mapped value and executes the registered tool. The tool’s execution result is then associated with the configured output variable. This allows a workflow to connect tool execution to later nodes:
The important distinction is that parameter mapping controls the inputs to the tool, while ToolResult represents the result of the tool execution.

Agent and Tool Results

Tool results and agent results serve different purposes. A tool execution uses:
while an agent execution uses the agent execution result defined by the BindAI agent runtime. When working directly with a ToolResult, use:
Do not assume that an agent result and a tool result have identical fields or behavior.

Tool Results and Connection-backed Tools

BindAI V1 also uses ToolResult for connection-backed tools. For example, the V1 Webhook connection is exposed to workflows as a connection-backed tool. Its tool implementation returns a ToolResult:
If the connection operation fails, it returns a failed result:
This means the workflow does not need a separate result type for a normal project tool and a connection-backed tool. Both use the same tool result contract.

Studio API Representation

The workflow runtime can contain rich Python objects such as ToolResult. The Studio HTTP API converts these runtime values into JSON-safe data before returning them to an API client. For a successful ToolResult, the Studio API exposes the underlying successful value. For example, a runtime result such as:
can be represented through the Studio API as:
A failed ToolResult is represented with failure information. For example:
can be exposed as:
This conversion happens at the API boundary. It does not change the workflow runtime’s internal ToolResult contract.

ToolResult and ExecutionResult

ToolResult extends BindAI’s ExecutionResult:
This allows tool results to participate in BindAI’s broader execution-result model while still providing tool-specific fields:
The inheritance relationship is useful when tool execution is part of a larger runtime operation, such as workflow execution. It does not mean that all execution-result types have exactly the same application-level fields or semantics.

Current API

The verified V1 ToolResult API is:
Constructor:
Class methods:
and:
The primary attributes are:
Example:
Then:

What Is Not Part of the V1 ToolResult API

The V1 API does not require a separate ToolExecutor abstraction. There is no verified V1 executor.py implementation in bindai-tool. Therefore, application code should not depend on an API such as:
or:
unless such an abstraction is introduced by a later BindAI version. Likewise, do not assume additional result helper methods that are not part of the verified API. The verified convenience methods are:

Predictable Tool Values

Tool outputs should be designed with their downstream consumers in mind. For structured operations, predictable dictionaries can be useful:
The successful value can then be accessed through:
and, when appropriate:
Keep output structures stable when other tools or workflow nodes depend on them.

Error Messages

Tool errors can flow into workflows, applications, or API responses. Avoid exposing sensitive information such as:
  • API keys
  • access tokens
  • passwords
  • connection credentials
  • private connection strings
  • sensitive personal information
For example, prefer:
over exposing an underlying credential or authentication header. Error messages should provide enough information to understand the failure while remaining safe for the layer that will consume the result.

Testing Tool Results

Tools should be tested for both successful and failed execution. A successful result:
A failed result:
It is also useful to test successful execution with a None value:
This verifies that callers do not incorrectly interpret None as failure.

Best Practices

  • Use ToolResult.ok(...) for successful class-based tool execution.
  • Use ToolResult.failed(...) for explicit tool failures.
  • Check result.success before consuming the result.
  • Read successful values from result.value.
  • Read failure information from result.error.
  • Do not use value is None as the success test.
  • Keep tool output structures predictable.
  • Keep error messages useful but safe.
  • Do not expose credentials or sensitive data through errors.
  • Test both successful and failed execution.
  • Remember that ToolResult extends ExecutionResult.
  • Treat workflow ToolResult values as runtime objects rather than assuming they are already JSON.
  • Let the Studio API perform the JSON conversion at the HTTP boundary.

Complete Example

A class-based tool can return ToolResult directly:
The successful execution produces:
A failure produces:
The caller can handle both cases through the same interface:

Summary

ToolResult is BindAI’s V1 result type for tool execution. Its core structure is:
Successful results can be created with:
Failed results can be created with:
The primary interface is:
ToolResult extends ExecutionResult, allowing tool results to participate in BindAI’s broader execution model. In workflows, the runtime can preserve the full ToolResult object, while the Studio API converts runtime values into JSON-safe responses for HTTP clients. The result contract therefore remains consistent across project tools, workflow Tool nodes, and the V1 Webhook connection-backed tool.